﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure;
using Model.Borrowers;

namespace Application.Services
{
    /// <summary>
    /// 
    /// </summary>
    public class BorrowerService
    {
       
        private IUnitOfWork uow;

        public BorrowerService()
        {
            uow = new UnitOfWork();
        }


        public BorrowerService(IUnitOfWork unitOfWork)
        {
            uow = unitOfWork;
        }


        public void Save(Borrower borrower)
        {

            if (borrower.IsValid == false)
            {
                throw new ArgumentException(
                    String.Format("This borrower is invalid and cannot be saved in its present state. '{0}'", borrower.BrokenRulesAsString));
            }
         
            using (uow)
            {
                uow.BorrowerRepository.Save(borrower);
                uow.SetComplete();
            }
           
        }

        
       
    }
}
